package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 数据字典-决策关系
 *
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/26 13:57
 * @since v1.0
 */
@Getter
public enum RelationshipEnum {

    // 决策关系
    KEY_DECISION_MAKERS("1", "enum.relationship.name.key_decision_makers", "keyDecisionMakers"),


    DECISION_MAKER("2", "enum.relationship.name.decision_maker", "decisionMaker"),


    BUSINESS_DECISION_MAKER("3", "enum.relationship.name.business_decision_maker", "businessDecisionMaker"),


    TECHNOLOGICAL_DECISION_MAKER("4", "enum.relationship.name.technological_decision_maker", "technologicalDecisionMaker"),


    FINANCIAL_DECISION_MAKER("5", "enum.relationship.name.financial_decision_maker", "financialDecisionMaker"),


    USE_PERSON("6", "enum.relationship.name.use_person", "usePerson"),


    OPINION_INFLUENCE_PERSON("7", "enum.relationship.name.opinion_influence_person", "opinionInfluencePerson"),


    ORDINARY_PERSON("8", "enum.relationship.name.ordinary_person", "ordinaryPerson"),
    ;

    private String code;
    private String name;
    private String attr;

    RelationshipEnum(String code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return RelationshipEnum
     */
    public static RelationshipEnum getByCode(String code) {
        for (RelationshipEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
